package br.edu.fatec.tutorial2d;

import android.graphics.Bitmap;

public class GraphicObject {

	private Bitmap bitmap;
	private Coordinates coordinates;
	private Speed speed;

	public GraphicObject(Bitmap bm) {
		bitmap = bm;
		coordinates = new Coordinates();
		speed = new Speed();
	}

	public Bitmap getBitmap() {
		return bitmap;
	}

	public Coordinates getCoordinates() {
		return coordinates;
	}
	
	public Speed getSpeed() {
		return speed;
	}

	public class Coordinates {
		private int x;
		private int y;

		public int getX() {
			return x + bitmap.getWidth() / 2;
		}

		public void setX(int value) {
			x = value - bitmap.getWidth() / 2;
		}

		public int getY() {
			return y + bitmap.getHeight() / 2;
		}

		public void setY(int value) {
			y = value - bitmap.getHeight() / 2;
		}

		@Override
		public String toString() {
			return "Coordinates: (" + x + ", " + y + ")";
		}
	}
	
	public class Speed {
		public static final int X_DIRECTION_RIGHT = 1;
		public static final int X_DIRECTION_LEFT = -1;
		public static final int Y_DIRECTION_DOWN = -1;
		public static final int Y_DIRECTION_UP = 1;
		
		private int x = 10;
		private int y = 10;
		
		private int xDirection = X_DIRECTION_RIGHT;
		private int yDirection = Y_DIRECTION_DOWN;
		
		public int getX() {
			return x;
		}
		
		public void setX(int speed) {
			x = speed;
		}
		
		public int getY() {
			return y;
		}
		
		public void setY(int speed) {
			y = speed;
		}
		
		public int getXDirection() {
			return xDirection;
		}
		
		public void setXDirection(int direction) {
			xDirection = direction;
		}
		
		public int getYDirection() {
			return yDirection;
		}
		
		public void setYDirection(int direction) {
			yDirection = direction;
		}
		
		public void toggleXDirection() {
			if (xDirection == X_DIRECTION_RIGHT) {
				xDirection = X_DIRECTION_LEFT;
			}else {
				xDirection = X_DIRECTION_RIGHT;
			}
		}
		
		public void toggleYDirection() {
			if (yDirection == Y_DIRECTION_DOWN) {
				yDirection = Y_DIRECTION_UP;
			}else {
				yDirection = Y_DIRECTION_DOWN;
			}
		}
		
		@Override
		public String toString() {
			return "Speed: x " + x + " | y: " + y + " | xDirection:" + (xDirection == X_DIRECTION_RIGHT? "RIGHT" : "LEFT");
		}
		
	}

}
